//================================================================================
// Filename: NavigationBar.as
// Authour: Jacky Fong
// Description:
// NavigationBar UI attaching to NavigationBarPlugin
//================================================================================

package
{
	import flash.display.MovieClip;
	import flash.events.*;
	import NavigationBarPlugin;
	
	public class NavigationBar extends MovieClip
	{
		private var _plugin:NavigationBarPlugin;
		
		function NavigationBar()
		{
			trace( "Init NavigationBar" );
			_show( mcNBHome );
			_setupEventListeners();
		}
		
		public function set plugin( pi:NavigationBarPlugin ):void
		{
			_plugin = pi;
		}
		
		private function _setupEventListeners():void
		{
			mcHome.addEventListener( MouseEvent.ROLL_OVER, _onRollOver );
			mcStory.addEventListener( MouseEvent.ROLL_OVER, _onRollOver );
			mcInvitation.addEventListener( MouseEvent.ROLL_OVER, _onRollOver );
			mcPhoto.addEventListener( MouseEvent.ROLL_OVER, _onRollOver );
			mcGuestbook.addEventListener( MouseEvent.ROLL_OVER, _onRollOver );
			
			mcHome.addEventListener( MouseEvent.ROLL_OUT, _onRollOut );
			mcStory.addEventListener( MouseEvent.ROLL_OUT, _onRollOut );
			mcInvitation.addEventListener( MouseEvent.ROLL_OUT, _onRollOut );
			mcPhoto.addEventListener( MouseEvent.ROLL_OUT, _onRollOut );
			mcGuestbook.addEventListener( MouseEvent.ROLL_OUT, _onRollOut );			
		}
		
		private function _onRollOver( evt:MouseEvent ):void
		{
			switch( evt.target ) {
				case mcHome: _show( mcNBHome ); break;
				case mcStory: _show( mcNBStory ); break;
				case mcInvitation: _show( mcNBInvitation ); break;
				case mcPhoto: _show( mcNBPhoto ); break;
				case mcGuestbook: _show( mcNBGuestbook ); break;
			}
		}
		
		private function _onRollOut( evt:MouseEvent ):void
		{
			if( _plugin == null ) return;
			// set to current page
			switch( _plugin.curPage ) {
				case "home": _show( mcNBHome ); break;
				case "story": _show( mcNBStory ); break;
				case "invitation": _show( mcNBInvitation ); break;
				case "photo": _show( mcNBPhoto ); break;
				case "guestbook": _show( mcNBGuestbook ); break;
			}
		}
		
		private function _hideAll():void
		{
			mcNBHome.visible = false;
			mcNBStory.visible = false;
			mcNBInvitation.visible = false;
			mcNBPhoto.visible = false;
			mcNBGuestbook.visible = false;
		}
		
		// show mc only, hide others
		private function _show( mc:MovieClip ):void
		{
			_hideAll();
			mc.visible = true;
		}
	}
}